package com.debao;

import com.debao.common.core.controller.BaseController;
import com.debao.common.core.domain.AjaxResult;
import com.debao.common.core.page.TableDataInfo;
import com.debao.common.utils.SecurityUtils;
import com.debao.system.domain.JoinOrder;
import com.debao.system.service.IJoinOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 教练入住订单
 */
@RestController
@RequestMapping("/api/joinOrder")
@CrossOrigin
public class ApiJoinOrder extends BaseController {

    @Autowired
    private IJoinOrderService joinOrderService;

    /**
     * 我的定金订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(JoinOrder joinOrder) {
        joinOrder.setUserId(SecurityUtils.getUserId());
        startPage();
        return getDataTable(joinOrderService.selectJoinOrderList(joinOrder));
    }

    /**
     * 获取入住订单详情
     */
    @GetMapping("/info/{id}")
    public AjaxResult info(@PathVariable("id") Long id) {
        return AjaxResult.success(joinOrderService.selectJoinOrderById(id));
    }
    /**
     * 订单是否支付成功
     * @param orderNo
     * @return
     */
    @GetMapping("/isPaySuccess/{orderNo}")
    public AjaxResult isPaySuccess(@PathVariable("orderNo") String orderNo) {
        return AjaxResult.success( joinOrderService.isPaySuccess(orderNo));
    }
    /**
     * 根据订单号和userid查询订单是否存在
     */
    @GetMapping("/isPay")
    public AjaxResult isPay(){
        Long userId = SecurityUtils.getUserId();
        boolean pay = joinOrderService.isPay(userId);
        return AjaxResult.success(pay);
    }

}
